/**
 * 定义站点地图模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.sw.bcMonitorParamDict.bcMonitorParamDictManager', ['water.entity.bcMonitorParamDict']);
		
	module.controller('bcMonitorParamDictManagerController',function($scope,$bcMonitorParamDictService){
		
		/**
		 * 设备列表数据
		 */
		$scope.paramList;
		
		/**
		 * 是否显示列表
		 */
		$scope.isShowList = true;
		/**
		 * 是否显示新建页面
		 */
		$scope.isShowAdd = false;
		/**
		 * 是否显示编辑页面
		 */
		$scope.isShowEdit = false;
		
		/**
		 * 用于新建的model
		 */
		$scope.addModel;
		/**
		 * 用于编辑的model
		 */
		$scope.editModel;

        /**
         * 是否计算排放量
         */
        $scope.calEmissionsSelections = [{"k":"0","v":"是"},
            {"k":"1","v":"否"}];

        /**
		 * 是否量程转换
         */
        $scope.isRangeConversionSelections = [{"k":"0","v":"是"},
            {"k":"1","v":"否"}];
		
        /**
         * 取值规则
         */
        $scope.valueRules = [{"k":"1","v":"当前值"},
                             {"k":"2","v":"算术平均"},
                             {"k":"3","v":"区间累计"},
            				 {"k":"4","v":"小时、天加权，分钟算术均值"},
       					     {"k":"5","v":"分钟,小时当前值，天数据加权"}];
        
        /**
         * 单位转换
         */
        $scope.unitConver = [{"k":"0","v":"乘倍数"},
                             {"k":"1","v":"除倍数"},
                             {"k":"2","v":"乘分子量除22.4"},
                             {"k":"3","v":"乘分子量除22.4乘倍数"},
                             {"k":"4","v":"乘分子量除22.4除倍数"}
                             ];

        
		/**
		 * 打开新增窗口按钮点击事件
		 */
		$scope.onOpenCreateClick = function(){
			$scope.addModel = {};
			$scope.showAdd();
		}
		
		/**
		 * 保存按钮点击事件
		 */
		$scope.onSaveClick = function(model){
			$bcMonitorParamDictService.create(model).then(function(){
				$scope.getList();
				$scope.showList();
				alert("保存成功");
				$scope._init();
			}).catch(function(error){
				console.log(error);
			});
		}
		
		/**
		 * 打开编辑窗口按钮点击事件
		 */
		$scope.onOpenEditClick = function(model){
			$scope.editModel = model;
			$scope.showEdit();
		}
		
		/**
		 * 删除按钮点击事件
		 */
		$scope.onDeleteClick = function(id){
			$bcMonitorParamDictService.deleteModel(id).then(function(){
				$scope.getList();
				alert("删除成功!");
				$scope._init();
			});
		}
		
		/**
		 * 更新按钮点击事件
		 */
		$scope.onUpdateClick = function(model){
			$bcMonitorParamDictService.update(model).then(function(){
				$scope.getList();
				$scope.showList();
				alert("保存成功");
				$scope._init();
			}).catch(function(error){
				console.log(error);
			});
		}
		
		/**
		 * 只显示列表
		 */
		$scope.showList = function(){
			$scope.isShowList = true;
			$scope.isShowAdd = false;
			$scope.isShowEdit = false;
		}
		
		/**
		 * 只显示新建页
		 */
		$scope.showAdd = function(){
			$scope.isShowList = false;
			$scope.isShowAdd = true;
		}

        /**
         * 关闭新建页
         */
        $scope.closeAdd = function(){
            $scope.isShowAdd = false;
            $scope.isShowList = true;
        }
		
		/**
		 * 只显示编辑页
		 */
		$scope.showEdit = function(){
			$scope.isShowList = false;
			$scope.isShowEdit = true;
		}

        /**
		 * 关闭编辑页
         */
        $scope.closeEdit = function(){
            $scope.isShowEdit = false;
            $scope.isShowList = true;
        }


		
		$scope.getList = function(){
			$bcMonitorParamDictService.getList().then(function(data){
				data.forEach(function (data) {
                    /**
					 * 取值规则翻译
                     */
                    $scope.valueRules.forEach(function(item) {
                        if(data.VALUE_RULE===item.k){
                            data.VALUE_RULE_SHOW = item.v;
                        }
                    });
                    /**
                     * 单位转换翻译
                     */
                    $scope.unitConver.forEach(function (item) {
                        if(data.UNIT_CONVER===item.k){
                            data.UNIT_CONVER_SHOW = item.v;
                        }
                    });
                    /**
					 * 是否计算排放量翻译
                     */
                    $scope.calEmissionsSelections.forEach(function (item) {
                        if(data.CAL_EMISSIONS===item.k){
                            data.CAL_EMISSIONS_SHOW = item.v;
                        }
                    });
                    /**
					 * 是否量程转换翻译
                     */
                    $scope.isRangeConversionSelections.forEach(function (item) {
                        if(data.IS_RANGE_CONVERSION===item.k){
                            data.IS_RANGE_CONVERSION_SHOW = item.v;
                        }
                    });
                });
				$scope.paramList = data;
			});
		}
		
		$scope._init = function(){
			$scope.getList();
			$scope.showList();
		}
		
		$scope._init();

	});
	
}(window, angular));


